package lib.servlet;

import lib.Dao.Dbutil;
import lib.Dao.SchoolDAO;
import lib.Model.School;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ttop5 on 16-4-22.
 */
@WebServlet(urlPatterns = "/schoolsearch", name = "schoolsearch")
public class SchoolSearchServlet extends HttpServlet{
    Dbutil dbutil = new Dbutil();
    SchoolDAO schoolDAO=new SchoolDAO();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String content = new String(req.getParameter("content").getBytes("ISO-8859-1"), "UTF-8");

        List<School> schoolList=new ArrayList<>();

        System.out.println(content);
        try {

            //schoolList= schoolDAO.getSchool();

            schoolList= schoolDAO.getSchoollike(content);

             //JSONArray data = JSONArray.fromObject(schoolList);
            //System.out.println(data);
            req.setAttribute("list", schoolList);
            //System.out.println(schoolList);

            req.getRequestDispatcher("/page/dept/setse.jsp").forward(req, resp);
            //resp.sendRedirect("/page/dept/qrcode.jsp");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
